package com.tan.kotlintest.changeskin;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.tan.kotlintest.R;

import java.util.ArrayList;
import java.util.List;


/*
 * Copyright (C)
 * 版权所有
 *
 * 功能描述：测试setFactory2 换肤
 * 作者：txj
 * 创建时间：2019/2/18
 *
 * 修改人：
 * 修改描述：
 * 修改日期
 */
public class TestSkinMainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_skin_main_layout);
        TextView test_one_tv = findViewById(R.id.test_one_tv);
        test_one_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), TestSetFactory2Activity.class);
                startActivity(intent);
            }
        });
        TextView test_chang_skin_tv = findViewById(R.id.test_chang_skin_tv);
        test_chang_skin_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), TestChangeSkinActivity.class);
                startActivity(intent);
            }
        });
        checkPermission();
    }

    protected void checkPermission() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            List<String> permissions = new ArrayList<>();
            if (PackageManager.PERMISSION_GRANTED != ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
            }
            if (PackageManager.PERMISSION_GRANTED != ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.READ_EXTERNAL_STORAGE)) {
                permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
            }
            if (permissions.size() != 0) {
                ActivityCompat.requestPermissions(this, permissions.toArray(new String[0]), 100);
            }
        }
    }

}
